package com.macro.mall.portal.service.impl;

import com.macro.mall.domain.PmsAlbumPicResult;
import com.macro.mall.domain.UploadResult;
import com.macro.mall.mapper.PmsAlbumPicMapper;
import com.macro.mall.model.PmsAlbumPic;
import com.macro.mall.model.PmsAlbumPicExample;
import com.macro.mall.portal.root.upload.UploadFileService;
import com.macro.mall.portal.service.PmsAlbumPicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.xml.crypto.Data;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

@Service
@Transactional
public class PmsAlbumPicServiceImpl extends UploadFileService implements PmsAlbumPicService {

    @Autowired
    private PmsAlbumPicMapper pmsAlbumPicMapper;

    @Override
    public PmsAlbumPicResult saveMassage(File file) {
        PmsAlbumPicResult uploadResult = new PmsAlbumPicResult();
        uploadResult.setId(null);
        uploadResult.setPic(file.getPath());
        uploadResult.setCreateTime(new Date());
        pmsAlbumPicMapper.insert(uploadResult);
        return uploadResult;
    }

    @Override
    public List<PmsAlbumPic> getPmsAlbumPic(Long productId) {
        PmsAlbumPicExample pmsAlbumPicExample = new PmsAlbumPicExample();
        PmsAlbumPicExample.Criteria criteria = pmsAlbumPicExample.createCriteria();
        criteria.andAlbumIdEqualTo(productId);
        pmsAlbumPicExample.setOrderByClause("id desc");
        return pmsAlbumPicMapper.selectByExample(pmsAlbumPicExample);
    }
}

